import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TestStackWidget extends StatefulWidget {
  const TestStackWidget({super.key});

  @override
  State<TestStackWidget> createState() {
    return _StackState();
  }
}

class _StackState extends State<TestStackWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("基础 Stack 学习使用 ,类似Android的FrameLayout"),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(">>>>>> 类似Android的FrameLayout"),
            ConstrainedBox(
                constraints: BoxConstraints(minWidth: double.infinity, minHeight: 300),
                child: Container(
                  color: Colors.blue,
                  child: Stack(
                    alignment: Alignment.center,
                    children: [
                      Positioned(
                        child: Text("未指定位置布局默认center"),
                      ),
                      Positioned(
                        left: 10,
                        top: 10,
                        child: Text("left=10,top=10"),
                      ),
                      Positioned(
                        right: 10,
                        bottom: 10,
                        child: Text("right=10,bottom=10"),
                      ),
                      Positioned(
                        width: 100,
                        left: 10,
                        bottom: 10,
                        child: Text("width=100"),
                      ),
                      Positioned(
                        width: 100,
                        height: 30,
                        right: 10,
                        top: 10,
                        child: Text("width=100,height=50"),
                      ),
                    ],
                  ),
                )),
            const Text(">>>>>> 类似Android的FrameLayout"),
            ConstrainedBox(
                constraints:
                    BoxConstraints(minWidth: double.infinity, minHeight: 100, maxHeight: 100),
                child: Container(
                  color: Colors.blue,
                  child: Stack(
                    alignment: Alignment.center,
                    fit: StackFit.expand,
                    children: [
                      Positioned(
                        child: Container(
                          color: Colors.blueGrey,
                          child: Text(
                            "未指定位置布局默认center",
                            style: TextStyle(backgroundColor: Colors.yellowAccent),
                          ),
                        ),
                      ),
                      Positioned(
                        left: 10,
                        top: 10,
                        child: Text("left=10,top=10"),
                      ),
                    ],
                  ),
                )),
          ],
        ),
      ),
    );
  }
}
